package com.web.dao;

import com.github.pagehelper.Page;
import com.web.controller.web.WebStoreController;
import com.web.entity.StoreChange;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

/**
 * @author FDjavaone
 */
public interface StoreChangeMapper {
    @Delete({
        "delete from t_store_change",
        " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into t_store_change (m_id, s_id, ",
        " type, merchant_name, ",
        " level, logo, licence_no, ",
        " licence_img, identity_a_img, ",
        " store_img, identity_b_img, ",
        " contactor, contact_phone, ",
        " contact_tel, province, ",
        " city, region, street, ",
        " address, lng, lat, ",
        " business_status,status, merchant_img,reason,refuse_reason, ",
        " create_time, modify_time)",
        " values (#{mId,jdbcType=BIGINT}, #{sId,jdbcType=BIGINT}, ",
        " #{type,jdbcType=VARCHAR}, #{merchantName,jdbcType=VARCHAR}, ",
        " #{level,jdbcType=VARCHAR}, #{logo,jdbcType=VARCHAR}, #{licenceNo,jdbcType=VARCHAR}, ",
        " #{licenceImg,jdbcType=VARCHAR}, #{identityAImg,jdbcType=VARCHAR}, ",
        " #{storeImg,jdbcType=VARCHAR}, #{identityBImg,jdbcType=VARCHAR}, ",
        " #{contactor,jdbcType=VARCHAR}, #{contactPhone,jdbcType=VARCHAR}, ",
        " #{contactTel,jdbcType=VARCHAR}, #{province,jdbcType=VARCHAR}, ",
        " #{city,jdbcType=VARCHAR}, #{region,jdbcType=VARCHAR}, #{street,jdbcType=VARCHAR}, ",
        " #{address,jdbcType=VARCHAR}, #{lng,jdbcType=DOUBLE}, #{lat,jdbcType=DOUBLE}, ",
        " #{businessStatus,jdbcType=INTEGER},#{status,jdbcType=INTEGER}, #{merchantImg,jdbcType=VARCHAR}, #{reason,jdbcType=VARCHAR},#{refuseReason,jdbcType=VARCHAR}, ",
        " #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(StoreChange record);

    @InsertProvider(type=StoreChangeSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(StoreChange record);

    @Select({
        "select",
        " id, m_id, s_id, type, merchant_name, level, logo, licence_no, licence_img, identity_a_img, ",
        " store_img, identity_b_img, contactor, contact_phone, contact_tel, province, ",
        " city, region, street, address, lng, lat, business_status, status, merchant_img,reason,refuse_reason, create_time, ",
        " modify_time",
        " from t_store_change",
        " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="m_id", property="mId", jdbcType=JdbcType.BIGINT),
        @Result(column="s_id", property="sId", jdbcType=JdbcType.BIGINT),
        @Result(column="type", property="type", jdbcType=JdbcType.VARCHAR),
        @Result(column="merchant_name", property="merchantName", jdbcType=JdbcType.VARCHAR),
        @Result(column="level", property="level", jdbcType=JdbcType.VARCHAR),
        @Result(column="logo", property="logo", jdbcType=JdbcType.VARCHAR),
        @Result(column="licence_no", property="licenceNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="licence_img", property="licenceImg", jdbcType=JdbcType.VARCHAR),
        @Result(column="identity_a_img", property="identityAImg", jdbcType=JdbcType.VARCHAR),
        @Result(column="store_img", property="storeImg", jdbcType=JdbcType.VARCHAR),
        @Result(column="identity_b_img", property="identityBImg", jdbcType=JdbcType.VARCHAR),
        @Result(column="contactor", property="contactor", jdbcType=JdbcType.VARCHAR),
        @Result(column="contact_phone", property="contactPhone", jdbcType=JdbcType.VARCHAR),
        @Result(column="contact_tel", property="contactTel", jdbcType=JdbcType.VARCHAR),
        @Result(column="province", property="province", jdbcType=JdbcType.VARCHAR),
        @Result(column="city", property="city", jdbcType=JdbcType.VARCHAR),
        @Result(column="region", property="region", jdbcType=JdbcType.VARCHAR),
        @Result(column="street", property="street", jdbcType=JdbcType.VARCHAR),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="lng", property="lng", jdbcType=JdbcType.DOUBLE),
        @Result(column="lat", property="lat", jdbcType=JdbcType.DOUBLE),
        @Result(column="business_status", property="businessStatus", jdbcType=JdbcType.INTEGER),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="merchant_img", property="merchantImg", jdbcType=JdbcType.VARCHAR),
        @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR),
        @Result(column="refuse_reason", property="refuseReason", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    StoreChange selectByPrimaryKey(Long id);

    @UpdateProvider(type=StoreChangeSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(StoreChange record);

    @Update({
        "update t_store_change",
        " set m_id = #{mId,jdbcType=BIGINT},",
          " s_id = #{sId,jdbcType=BIGINT},",
          " type = #{type,jdbcType=VARCHAR},",
          " merchant_name = #{merchantName,jdbcType=VARCHAR},",
          " level = #{level,jdbcType=VARCHAR},",
          " logo = #{logo,jdbcType=VARCHAR},",
          " licence_no = #{licenceNo,jdbcType=VARCHAR},",
          " licence_img = #{licenceImg,jdbcType=VARCHAR},",
          " identity_a_img = #{identityAImg,jdbcType=VARCHAR},",
          " store_img = #{storeImg,jdbcType=VARCHAR},",
          " identity_b_img = #{identityBImg,jdbcType=VARCHAR},",
          " contactor = #{contactor,jdbcType=VARCHAR},",
          " contact_phone = #{contactPhone,jdbcType=VARCHAR},",
          " contact_tel = #{contactTel,jdbcType=VARCHAR},",
          " province = #{province,jdbcType=VARCHAR},",
          " city = #{city,jdbcType=VARCHAR},",
          " region = #{region,jdbcType=VARCHAR},",
          " street = #{street,jdbcType=VARCHAR},",
          " address = #{address,jdbcType=VARCHAR},",
          " lng = #{lng,jdbcType=DOUBLE},",
          " lat = #{lat,jdbcType=DOUBLE},",
          " business_status = #{businessStatus,jdbcType=INTEGER},",
          " status = #{status,jdbcType=INTEGER},",
          " merchant_img = #{merchantImg,jdbcType=VARCHAR},",
          " reason = #{reason,jdbcType=VARCHAR},",
          " refuse_reason = #{refuseReason,jdbcType=VARCHAR},",
          " create_time = #{createTime,jdbcType=TIMESTAMP},",
          " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
        " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(StoreChange record);


    @Select({
            "select",
            " id, m_id, s_id, type, merchant_name, level, logo, licence_no, licence_img, identity_a_img, ",
            " store_img, identity_b_img, contactor, contact_phone, contact_tel, province, ",
            " city, region, street, address, lng, lat, business_status, status, merchant_img,reason,refuse_reason, create_time, ",
            " modify_time",
            " from t_store_change",
            " where  s_id= #{sId,jdbcType=BIGINT} and status=0"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="m_id", property="mId", jdbcType=JdbcType.BIGINT),
            @Result(column="s_id", property="sId", jdbcType=JdbcType.BIGINT),
            @Result(column="type", property="type", jdbcType=JdbcType.VARCHAR),
            @Result(column="merchant_name", property="merchantName", jdbcType=JdbcType.VARCHAR),
            @Result(column="level", property="level", jdbcType=JdbcType.VARCHAR),
            @Result(column="logo", property="logo", jdbcType=JdbcType.VARCHAR),
            @Result(column="licence_no", property="licenceNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="licence_img", property="licenceImg", jdbcType=JdbcType.VARCHAR),
            @Result(column="identity_a_img", property="identityAImg", jdbcType=JdbcType.VARCHAR),
            @Result(column="store_img", property="storeImg", jdbcType=JdbcType.VARCHAR),
            @Result(column="identity_b_img", property="identityBImg", jdbcType=JdbcType.VARCHAR),
            @Result(column="contactor", property="contactor", jdbcType=JdbcType.VARCHAR),
            @Result(column="contact_phone", property="contactPhone", jdbcType=JdbcType.VARCHAR),
            @Result(column="contact_tel", property="contactTel", jdbcType=JdbcType.VARCHAR),
            @Result(column="province", property="province", jdbcType=JdbcType.VARCHAR),
            @Result(column="city", property="city", jdbcType=JdbcType.VARCHAR),
            @Result(column="region", property="region", jdbcType=JdbcType.VARCHAR),
            @Result(column="street", property="street", jdbcType=JdbcType.VARCHAR),
            @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
            @Result(column="lng", property="lng", jdbcType=JdbcType.DOUBLE),
            @Result(column="lat", property="lat", jdbcType=JdbcType.DOUBLE),
            @Result(column="business_status", property="businessStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
            @Result(column="merchant_img", property="merchantImg", jdbcType=JdbcType.VARCHAR),
            @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR),
            @Result(column="refuse_reason", property="refuseReason", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    StoreChange selectHasNotFinish(StoreChange storeChange);


    @SelectProvider(type = StoreChangeSqlProvider.class, method = "selectAllStoreChangeApply")
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="m_id", property="mId", jdbcType=JdbcType.BIGINT),
            @Result(column="s_id", property="sId", jdbcType=JdbcType.BIGINT),
            @Result(column="type", property="type", jdbcType=JdbcType.VARCHAR),
            @Result(column="merchant_name", property="merchantName", jdbcType=JdbcType.VARCHAR),
            @Result(column="level", property="level", jdbcType=JdbcType.VARCHAR),
            @Result(column="logo", property="logo", jdbcType=JdbcType.VARCHAR),
            @Result(column="licence_no", property="licenceNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="licence_img", property="licenceImg", jdbcType=JdbcType.VARCHAR),
            @Result(column="identity_a_img", property="identityAImg", jdbcType=JdbcType.VARCHAR),
            @Result(column="store_img", property="storeImg", jdbcType=JdbcType.VARCHAR),
            @Result(column="identity_b_img", property="identityBImg", jdbcType=JdbcType.VARCHAR),
            @Result(column="contactor", property="contactor", jdbcType=JdbcType.VARCHAR),
            @Result(column="contact_phone", property="contactPhone", jdbcType=JdbcType.VARCHAR),
            @Result(column="contact_tel", property="contactTel", jdbcType=JdbcType.VARCHAR),
            @Result(column="province", property="province", jdbcType=JdbcType.VARCHAR),
            @Result(column="city", property="city", jdbcType=JdbcType.VARCHAR),
            @Result(column="region", property="region", jdbcType=JdbcType.VARCHAR),
            @Result(column="street", property="street", jdbcType=JdbcType.VARCHAR),
            @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
            @Result(column="lng", property="lng", jdbcType=JdbcType.DOUBLE),
            @Result(column="lat", property="lat", jdbcType=JdbcType.DOUBLE),
            @Result(column="business_status", property="businessStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
            @Result(column="merchant_img", property="merchantImg", jdbcType=JdbcType.VARCHAR),
            @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR),
            @Result(column="refuse_reason", property="refuseReason", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Page<StoreChange> selectAllStoreChangeApply(WebStoreController.StoreApplyColumns storeApplyColumns);

    @Select({
            "select count(0) from t_store_change where status=0 "
    })
    int countWaiting();
}